﻿# 使用 ASP.NET Core 运行时镜像作为基础
FROM dotnet-base-10-aspnet:latest AS base
WORKDIR /app
EXPOSE 8080 5000 80 443

# 版本号
ARG APP_VERSION="1.0"
LABEL app.version="$APP_VERSION"
ENV APP_VERSION=$APP_VERSION

# 使用 dotnet-sdk-10-with-node 镜像来构建应用
FROM dotnet-sdk-10-with-node:latest AS build
WORKDIR /SageKing
COPY . .
RUN dotnet restore "src/SageKing.Blazor.OpenIdService/SageKing.Blazor.OpenIdService/SageKing.Blazor.OpenIdService.csproj"

# 构建扩展库 ,暂时取消，已提前提交 默认 wwwroot,如有变化请手动更新
#RUN cd "/SageKing/external/ant-design-blazor" && \
        #npm install && \
        #dotnet build "site/AntDesign.Docs.Build/AntDesign.Docs.Build.csproj"
#
#RUN cd "/SageKing/external/BlazorSize/BlazorSize" && \
        #npm install && npm run build

# 构建服务库
WORKDIR "/SageKing"
RUN dotnet build "src/SageKing.Blazor.OpenIdService/SageKing.Blazor.OpenIdService/SageKing.Blazor.OpenIdService.csproj" -c Release -f net10.0 -o /app/build

# 集成测试
#RUN dotnet test --configuration Release --no-build --verbosity normal

# 发布应用
FROM build AS publish
RUN dotnet publish "src/SageKing.Blazor.OpenIdService/SageKing.Blazor.OpenIdService/SageKing.Blazor.OpenIdService.csproj" --no-restore -c Release -f net10.0 -o /app/publish

# 生成最终镜像
FROM base AS final

# 设置时区环境变量
ENV TZ=Asia/Shanghai

WORKDIR /app
COPY --from=publish /app/publish .

# 递归删除配置目录文件-整个目录及其内容
RUN rm -rf /app/Configuration

ENTRYPOINT ["dotnet", "SageKing.Blazor.OpenIdService.dll"]